<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Computes the maximum-degree heuristic edge weights</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/graph_laplacian/html/max_deg.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Computes the maximum-degree heuristic edge weights</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="keyword">function</span> [w,rho] = max_deg(A)

<span class="comment">% [W,RHO] = MAX_DEG(A) gives a vector of maximum-degree edge weights for a</span>
<span class="comment">% graph described by the incidence matrix A (NxM). N is the number of</span>
<span class="comment">% nodes, and M is the number of edges. Each column of A has exactly one +1</span>
<span class="comment">% and one -1. RHO is computed from the weights W as follows:</span>
<span class="comment">%    RHO = max(abs(eig( eye(n,n) - (1/n)*ones(n,n) - A*W*A' ))).</span>
<span class="comment">%</span>
<span class="comment">% Maximum-degree edge weights are all equal to one over the maximum</span>
<span class="comment">% degree of the nodes in the graph.</span>
<span class="comment">%</span>
<span class="comment">% For more details, see the references:</span>
<span class="comment">% "Fast linear iterations for distributed averaging" by L. Xiao and S. Boyd</span>
<span class="comment">% "Fastest mixing Markov chain on a graph" by S. Boyd, P. Diaconis, and L. Xiao</span>
<span class="comment">% "Convex Optimization of Graph Laplacian Eigenvalues" by S. Boyd</span>
<span class="comment">%</span>
<span class="comment">% Almir Mutapcic 08/29/06</span>

<span class="comment">% maximum degree solution</span>
[n,m] = size(A);

<span class="comment">% max degrees of the nodes</span>
Lunw = A*A';        <span class="comment">% unweighted Laplacian matrix</span>
degs = diag(Lunw);

<span class="comment">% max degree weight allocation</span>
max_deg = max(degs);
w = (1/max_deg)*ones(m,1);

<span class="comment">% compute the norm</span>
<span class="keyword">if</span> nargout &gt; 1,
    rho = norm( eye(n) - A*diag(w)*A' - (1/n)*ones(n) );
<span class="keyword">end</span>
</pre>
</div>
</body>
</html>